from PyQt4.QtCore import Qt
from PyQt4.QtGui import QWidget, QLabel, QPixmap, QFont, QLineEdit, QFrame
from ..widgets.mixed_button import MixedButton
import screen_manager
from ..data import game_data

class NewGameScreen(QWidget):
	def __init__(self, *args, **kw):
		QWidget.__init__(self, *args, **kw)
		self.setGeometry(0, 0, 1024, 768)
		self.setObjectName("NewGameScreen")
#
#		sort out the font for later
#
		font = QFont("Gabrielle", 32)
#
#		do a fancy art decor thing for the top right corner
#
		pic = QLabel(self)
		pic.setGeometry((1024-412), 10, 402, 374)
		path = "resources/top_right_corner.png"
		pic.setPixmap(QPixmap(path))
#
#		same again for bottom left
#
		pic = QLabel(self)
		pic.setGeometry(10, (768-374-10), 402, 374)
		path = "resources/bottom_left_corner.png"
		pic.setPixmap(QPixmap(path))
#
#		stylesheet for caption/prompt
#
		ss = """
			QLabel#new_game_prompt {
				color		: yellow;
				font-size	: 32px;
			}
		"""
#
#		now the prompt itself
#
		prompt = QLabel(self)
		prompt.setObjectName("new_game_prompt")
		prompt.setText("Kindly Enter The Name Of Your\nFine Establishment")
		prompt.setGeometry(0, 220, 1024, 80)
		prompt.setStyleSheet(ss)
		prompt.setFont(font)
		prompt.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter )
#
#		QLineEdit is how Qt does input fields
#
#		let's have another stylesheet. We could probably combine these
#		at the parent widget level...
#
		ss = """
			QLineEdit {
				color: yellow;
				background-color: transparent;
				background-image: url(resources/input_frame.png);
				border: 1px solid transparent;
				text-align: center;
			}
			QLineEdit:focus {
				background-image: url(resources/input_frame_focus.png);
			}
		"""
#
#		we need a smaller font, so redo it.
#		could we just change the font size in the widget?
#
		font = QFont("Gabrielle", 24)
#
#		OK, this is the input. Note the centre alignment
#
		self.input = QLineEdit(self)
		self.input.setGeometry((1024-410)/2, 360, 410, 50)
		self.input.setStyleSheet(ss)
		self.input.setFont(font)
		self.input.setAlignment(Qt.AlignHCenter);	
#
#		using a frame to group buttons. a layout widget would be
#		better, but I couldn't get it to work
#
		width = 500
		frame = QFrame(self)
		frame.setGeometry((1024-width)/2, 500, width, 60)
#
#		OK, a "back" button
#
		back_butt = MixedButton("Back", frame)
		back_butt.setGeometry(0, 5, 210, 50)
		back_butt.clicked.connect(
			self.go_back
		)
#
#		and keeping up the victoriana feel of it all, 
#		a "forth" button
#
		forth_butt = MixedButton("Forth", frame)
		forth_butt.setGeometry(width-210, 5, 210, 50)
		forth_butt.clicked.connect(
			self.go_forward
		)
#
#		lastly, hide the window until we're ready for it
#
		self.hide()

	def go_back(self):
		screen_manager.show("main menu")

	def go_forward(self):
#
#		first find out what the input box says
#
		brothel_name = self.input.text().trimmed()
#
#		a null string warrants an popup error
#
		if brothel_name == "":
			msg = "In order to proceed, you should first\n"
			msg += "name your establishment."
			screen_manager.message_box(msg)
			return
#
#		reset any pre-existing game data and
#		buy the first brothel
#
		game_data.data.reset()
		game_data.data.buy_brothel(brothel_name)
		screen_manager.show("main screen")


